$(function(){

    let allchar =[0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e",
    "f","g","h","i","j","k","l","m","n","o","p","q","r",
    "s","t","u","v","w","x","y","z","A","B","C","D","E",
    "F","G","H","I","J","K","L","M","N","O","P","Q","R",
    "S","T","U","V","W","X","Y","Z"];
    let result = '';
    randomChar()
    let form={
        user:false,
        pwd:false,
        pwdagin:false
    }
    /**用户名判断 */
    $('.user').blur(function(){
        let reg = /^[a-zA-Z]\w{5,11}$/
        let uVal = $(this).val();
        let result = reg.test(uVal)
        if(result){
            $('.usermsg').text('');
            form.user= true;

        }else{
            $('.usermsg').text('6-12位字母开头，后面跟字母、数字、下划线')
        }
    })
    /**密码 */
    $('.pwd').blur(function(){
        let reg = /^[a-zA-Z]\w{5,11}$/
        let pVal = $(this).val();
        let result = reg.test(pVal)
        if(result){
            $('.pwdmsg').text('')
            form.pwd = true;
        }else{
            $('.pwdmsg').text('6-12位字母开头，后面跟字母、数字、下划线')
        }
    })
    /**再次匹配 */
    $('.pwdagin').blur(function(){
        let pVal=$('.pwd').val()
        if($(this).val()!==pVal){
            $('.pwdaginmsg').text('两次输入的密码不同')
        }else{
            form.pwdagin=true;
        }
    })

    /**获取随机的验证码 */
    
    function randomChar(){
        result = '';
        for(let i=0 ;i<4 ;i++){
            let index=Math.floor(Math.random()*62)
            result +=allchar[index]//这里已经重新赋值了
        }
     $('.textnumber').text(result)   
    }
    $('.register-btn').click(function(){
        if(!form.user){
            $('.user').blur()
        }else if(!form.pwd){
            $('.pwd').blur()
        }else if(!form.pwdagin){
            $('.pwdagin').blur()
        }else{
            //$('.textnumber').text(result)是一个方法 这是给span重新赋值   $('.textnumber').text()才是获取它的值

            //console.log($('.textnumber').text(result),$('.text-identify').val(),result);
            //这里应该和reslut比较
            if($('.text-identify').val()!==$('.textnumber').text()){
                // console.log($('.text-identify').val()!==$('.textnumber').text());
                //console.log(result);
                alert('验证码错误')
                randomChar();
                $('.text-identify').text('')
            }else{
                location.href='../page/sign.html'
            }
        }
        
        
    })

})